#ifndef __CAMERA_CTRL_H__
#define __CAMERA_CTRL_H__

struct CameraData
{
	nieIK::Vector3 m_pos;
	nieIK::Matrix4x4 m_rot;

	CameraData()
	{
	}

	void Init(const nieIK::Vector3 &pos, const nieIK::Matrix4x4 rot)
	{
		m_pos = pos;
		m_rot = rot;
	}

	void RotateAxis(const nieIK::Line &axis, float angle)
	{
		if (axis.dir.IsEqual(nieIK::Vector3(.0f)))
		{
			return;
		}
		RotatePointByLine(m_pos, m_pos, axis, angle);

		nieIK::Matrix4x4 mat;
		nieIK::Vector3 dir = axis.dir;
		dir.Normalize();

		MakeMatRotation(mat, dir, angle);
		m_rot *= mat;
	}

};

class CameraCtrl
{
public:
	
	CameraCtrl();

	void OnRbuttonDown(int x, int y);
	void OnRbuttonUp(int x, int y);
	void OnMouseMove(int x, int y);
	void OnMouseWheel(short zDelta);

	void InitCamera(const nieIK::Vector3 &pos,
		const nieIK::Vector3 &forward, 
		const nieIK::Vector3 &up);

	const nieIK::Matrix4x4& GetCameraRot() const;
	const nieIK::Vector3& GetCameraPos() const;

protected:

	void MouseRotateCamera(int x, int y);

	CameraData m_camera_data;
	bool m_rbtn_down;
	nieIK::Point2 m_mouse_pos_down;
	nieIK::Matrix4x4 m_cam_rot_mat_down;
	nieIK::Vector3 m_cam_to_origin_down;
	nieIK::Vector3 m_cam_to_origin;
	
};

#endif //__CAMERA_CTRL_H__